CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
SET(CMAKE_C_STANDARD 11)
PROJECT(BrainFuck C)

OPTION(build_with_rpath "Set CMAKE_BUILD_WITH_INSTALL_RPATH on" OFF)
OPTION(build_test "Build test program" ON)

ADD_DEFINITIONS(-DBF_VERSION="1.2.1 Version")
ADD_DEFINITIONS(-DBF_VERSION_INFO="Debug, hope that you are well.")

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)  # 设置输出路
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})

SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")  # 设定rpath
IF (build_with_rpath)
    SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
    MESSAGE("SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) success!")
ENDIF ()

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)

ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/src)
ADD_EXECUTABLE(BrainFuck main.c)
TARGET_LINK_LIBRARIES(BrainFuck BrainFuck_Lib)

IF (build_test)
    ENABLE_TESTING()
    ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/test)
    MESSAGE("Build test program")
ENDIF()

INSTALL(TARGETS BrainFuck)
